package gui;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;

/**
 * description: MainWindow
 * 主窗口
 * 
 * @author what-is-me
 * @date 2022/1/3 23:35
 */
public class MainWindow {
    public static JFrame frm = new JFrame("投资管理系统");
    public static Component p;

    public static void init() {
        /**
         * Description: init
         * 初始化主窗口
         * 
         * @param :
         * @return
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:35
         */
        frm.setIconImage(new ImageIcon("resource/icon.jpg").getImage());
        frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frm.setSize(480, 270);
        frm.setResizable(false);
        p = new Login();
        frm.add(p);
        frm.setVisible(true);
        frm.setLocationRelativeTo(null);
    }

    public static void update(Component pa) {
        /**
         * Description: update
         * 更新主窗口页面
         * 
         * @param pa:java.awt.Component
         * @return
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:36
         */
        frm.remove(p);
        p = pa;
        frm.add(p);
        frm.setVisible(true);
    }

    public static void Larger() {
        /**
         * Description: Larger
         * 放大并居中
         * 
         * @param :
         * @return
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:36
         */
        frm.setSize(1080, 720);
        int windowWidth = frm.getWidth();
        int windowHeight = frm.getHeight();
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize = kit.getScreenSize();
        int screenWidth = screenSize.width;
        int screenHeight = screenSize.height;
        frm.setLocation(screenWidth / 2 - windowWidth / 2, screenHeight / 2 - windowHeight / 2);
    }

    @Deprecated
    public static void setSizeChangable() {
        /**
         * Description: setSizeChangable
         * 页面大小可变
         * 
         * @param :
         * @return
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:37
         */
        frm.setResizable(true);
    }
}